package nl.ru.rd.facedetection.nnbfd;

/**
 * A window object, representing one window of a Matrix.
 * 
 * @author Christiaan Thijssen s0814970
 * @author Kevin Reintjes s0814954
 * @author Wouter Geraedts (s0814857 - wgeraedts) PGP 66AA5935
 */
public class Window
{
	/**
	 * Dimensions of every Window
	 */
	public static final short size = 20;

	private Matrix matrix;
	private int scale;
	private int x;
	private int y;

	/**
	 * The window constructor for creating a window.
	 * 
	 * @param matrix
	 *            The matrix the window is part of.
	 * @param scale
	 *            The scale of the window compared to the original image and original window size.
	 * @param x
	 *            The x position in the image.
	 * @param y
	 *            The y position in the image.
	 */
	public Window(Matrix matrix, int scale, int x, int y)
	{
		this.matrix = matrix;
		this.scale = scale;
		this.x = x;
		this.y = y;
	}

	/**
	 * @return The matrix the window is part of.
	 */
	public Matrix getSourceMatrix()
	{
		return this.matrix;
	}

	/**
	 * @return The x position in the image.
	 */
	public int getPosX()
	{
		return x;
	}

	/**
	 * @return The y position in the image.
	 */
	public int getPosY()
	{
		return y;
	}

	/**
	 * Creates the submatrix from the parent matrix as defined by the properties of this Window.
	 * 
	 * @return The window as an matrix.
	 */
	public Matrix getMatrix()
	{
		Matrix windowMatrix = new Matrix(size, size);
		for(int x = 0; x < size; x++)
			for(int y = 0; y < size; y++)
				windowMatrix.setValue(x, y, this.matrix.getValue(x + this.x, y + this.y));

		return windowMatrix;
	}

	/**
	 * @return the scale
	 */
	public int getScale()
	{
		return this.scale;
	}
}